import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

/* 路由列表 */
const routes = [
  {
    path: '/list',
    meta: {
      title: '商品列表'
    },
    name: 'list',
    component: () => import('../views/ListView.vue')
  },
  {
    path: '/cart',
    meta: {
      title: '购物车'
    },
    name: 'cart',
    component: () => import('../views/CartView.vue')
  },

  {
    path: '/product/:id',
    meta: {
      title: '商品详情'
    },
    component: () => import('../views/ProductView.vue')
  },
  {
    path: '*',
    redirect: '/list'
  }
]

// 路由配置
const RouterConfig = {
  mode: 'history', // 使用 HTML5 的 History 路由模式
  routes: routes
};
const router = new VueRouter(RouterConfig);

// router.beforeEach((to, from, next) => {
//   window.document.title = to.meta.title;
//   next();
// });

// router.afterEach((to, from, next) => {
//   window.scrollTo(0, 0);
// });


export default router
